mui.init();

mui.plusReady(function () {
    var self = plus.webview.currentWebview();
    var mob_code = self.code;
    var mobile  = self.mobile;

	var username = document.getElementById('username');    
	var password = document.getElementById('password');
	var register = document.getElementById('register');
	
	register.addEventListener('tap',function(){
		if(username.value.length == 0){
			plus.ui.toast('用户名不能为空');
			return false;
		}else if(password.value.length == 0){
            plus.ui.toast('密码不能为空');
            return false;
        }else{
            plus.nativeUI.showWaiting('正在注册中...');
            var api_host = plus.storage.getItem('HOST_URL');
            var name = username.value;
            var pass = password.value;
            mui.ajax({
                url:api_host+'/api/linxuan/user/register',
                data:{'mobile':mobile,'username':name,'password':pass},
                dataType:'json',
                type:'post',
                timeout:5000,
                success:function(msg){
                    if(msg.code == 1){
                        plus.nativeUI.closeWaiting();
                        mui.toast(msg.msg,{ duration:'1500', type:'div'});
                        setTimeout(function () {
                            mui.openWindow({
                                url: "login.html",
                                id:'loginHtml',
                            })
                        },2000)
                    }else{
                        plus.nativeUI.closeWaiting();
                        mui.toast(msg.msg,{ duration:'2000', type:'div'});
                    }
                },
                error:function(xhr,type,errorThrown){
                    plus.nativeUI.closeWaiting();
                    mui.toast('注册账号失败，请联系客服！',{ duration:'2000', type:'div'});
                }
            });
		}

	});
});